#ifndef SGU_EXCEPTION_H
#define SGU_EXCEPTION_H

SGU_NS_BEGIN


//! Generic exception
class Exception
{
	public:

	#ifdef SGU_DEBUG
	//! Default constructor for DEBUG
	Exception(const char * file, int line) : _file(file), _line(line) {}
	#else
	//! Default constructor
	Exception() {}
	#endif

	virtual ~Exception() {}

	//! Descriptive full text
	const std::string text() const;

	
	protected:
	//! Descriptive text generator
	virtual std::string vtext() const = 0;

	private:
	#ifdef SGU_DEBUG
	std::string _file;
	int _line;
	#endif
 

};

//! Exception encapsulating \c errno
class ErrException : public Exception
{
	public:

	#ifdef SGU_DEBUG
	//! Constructor for DEBUG
	ErrException(int e, const char * file, int line) : Exception(file,line), _err(e) {}
	#else
	//! Constructor
	ErrException(int e) : _err(e) {}
	#endif

	virtual ~ErrException() {}

	//! Get errno
	int err() const {return _err;}


	protected:
	virtual std::string vtext() const;

	private:
	int _err;

};


//! SGU exception
class SGUException : public Exception
{
	public:

	#ifdef SGU_DEBUG
	//! Constructor for DEBUG
	SGUException(const std::string & t, const char * file, int line) : Exception(file,line), _text(t) {}
	//! Constructor for DEBUG
	SGUException(const char * t, const char * file, int line) : Exception(file,line), _text(t) {}
	#else
	//! Constructor
	SGUException(const std::string & t) : _text(t) {}
	//! Constructor
	SGUException(const char * t) : _text(t) {}
	#endif

	virtual ~SGUException() {}

	protected:
	virtual std::string vtext() const;

	private:
	std::string _text;

};


SGU_NS_END

#endif
